#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import shutil
import datetime

timestamp = datetime.datetime.strftime(datetime.datetime.now(), '%c')


def doRuleForm(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
            {}: "",
    '''
    return tp.format(cname, cinfo)


def doRule(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
        {}: [
          // {{ required: true, message: "不能为空", trigger: "blur" }}
        ],
    '''
    return tp.format(cname, cinfo)




def toJs(item):
    with open('./input/home.js') as f:
        tp = f.read()

        tnameLow = item['tname'].lower()
        tnameUp = tnameLow.upper()
        cols = item['cols']

        ruleForm = ("\n").join([doRuleForm(item) for item in cols])
        # print(ruleForm)

        rule = ("\n").join([doRule(item) for item in cols])
        # print(rule)

        txt = tp.replace('#ruleForm#', ruleForm).replace(
            '#tnameLow#', tnameLow).replace(
            '#tnameUp#', tnameUp).replace('#timestamp#', timestamp).replace('#rule#', rule)
        # print(txt)

        print('###', tnameLow,
              r'./output/llbb/{0}/{0}Home.js'.format(tnameLow))
        
        with open(r'./output/llbb/{0}/{0}Home.js'.format(tnameLow), 'w') as fi:
            fi.write(txt)


def main():
    pass


if __name__ == '__main__':
    # for i in range(15):
    #     main()
    #     print(',')
    main()
    # row = ('ACME', 50, 91.5)
    # print(*row, sep="**")
    print('----success')
